package b.sync.domain

import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.numeric._
import eu.timepit.refined.string._

trait DataSource {
  val driver: String Refined Trimmed
  val url: String
  val user: String Refined Trimmed
  val password: String
}

case class MySQL(
                  db: String Refined Trimmed,
                  user: String Refined Trimmed,
                  password: String = "",
                  host: String Refined Trimmed = "localhost",
                  port: Int Refined Positive = 3306,
                  driver: String Refined Trimmed = "com.mysql.cj.jdbc.Driver"
                ) extends DataSource {
  private val address: String = if (port.value == 3306) host else s"$host:$port"
  override val url = s"jdbc:mysql://$address/$db?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8"
}

trait DbSync {
  val ds: DataSource
}